package com.example.controller.admin;

import com.example.entity.CustomerVip;
import com.example.service.CustomerVipService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CustomerVip)表控制层
 *
 * @author makejava
 * @since 2024-05-18 18:53:59
 */
@RestController
@RequestMapping("/admin/customerVip")
@Slf4j
@Api(tags = "会员相关接口")
public class CustomerVipController {
    /**
     * 服务对象
     */
    @Resource
    private CustomerVipService customerVipService;

    /**
     * 分页查询
     *
     * @param customerVip 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<CustomerVip>> queryByPage(CustomerVip customerVip, PageRequest pageRequest) {
        return ResponseEntity.ok(this.customerVipService.queryByPage(customerVip, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CustomerVip> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.customerVipService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param customerVip 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<CustomerVip> add(CustomerVip customerVip) {
        return ResponseEntity.ok(this.customerVipService.insert(customerVip));
    }

    /**
     * 编辑数据
     *
     * @param customerVip 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<CustomerVip> edit(CustomerVip customerVip) {
        return ResponseEntity.ok(this.customerVipService.update(customerVip));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.customerVipService.deleteById(id));
    }

}

